<template>
  <Table
    ref="tableRef"
    :url="URL_PAGINGTICKET"
    :columns="data.columns"
    :toolbar="data.toolbar"
    :handles="data.handles"
    :query="data.query"
  ></Table>
</template>
  
<script lang="ts" setup name="ticketingManagementList">
import Table from '@/components/table/index.vue';
import { queryDicByParent } from '@/service/apis/api';
import { URL_PAGINGTICKET, EXPORT_TICKET } from '@/service/apis/financial';
import { exportFile } from '@/utils/utils';

const router = useRouter();

const tableRef = ref();
const emit = defineEmits(['get-update']);
onActivated(() => {
  emit('get-update', (flag: boolean) => {
    if (flag) {
      tableRef.value?.getData();
    }
  });
});

const data = reactive({
  columns: [
    {
      prop: 'companyName',
      label: '公司名称',
    },
    {
      prop: 'taxNumber',
      label: '税号',
    },
    {
      prop: 'ticketType',
      label: '发票形式',
      dic: [] as any,
      type: Number,
    },
    {
      prop: 'bankName',
      label: '开户行名称',
    },
    {
      prop: 'bankAccount',
      label: '开户行账号',
    },
    {
      prop: 'address',
      label: '注册地址',
    },
    {
      prop: 'telephone',
      label: '电话',
    },
    {
      prop: 'createTime',
      label: '创建时间 ',
    },
  ],
  toolbar: [
    {
      label: '导出',
      permission: 'ticketingManagementList.export',
      icon: 'icon-export',
      type: 'primary',
      plain: true,
      handle: (row: any) => {
        exportFile(EXPORT_TICKET, '票务管理', tableRef.value?.getForm());
      },
    },
  ],
  handles: [
    {
      label: '修改',
      permission: 'ticketingManagementList.edit',
      handle: (row: any) => {
        router.push({
          name: 'ticketingManagementEdit',
          query: { id: row.id },
        });
      },
    },
  ],
  query: [
    {
      label: '公司名称',
      prop: 'companyName',
      comName: 'input',
      props: {
        placeholder: '请输入公司名称',
      },
    },
    {
      label: '税号',
      prop: 'taxNumber',
      comName: 'input',
      props: {
        placeholder: '请输入税号',
      },
    },
    {
      label: '开户行名称',
      prop: 'bankName',
      comName: 'input',
      props: {
        placeholder: '请输入开户行名称',
      },
    },
    {
      label: '开户行账号',
      prop: 'bankAccount',
      comName: 'input',
      props: {
        placeholder: '请输入开户行账号',
      },
    },
    {
      label: '注册地址',
      prop: 'address',
      comName: 'input',
      props: {
        placeholder: '请输入注册地址',
      },
    },
    {
      label: '电话',
      prop: 'telephone',
      comName: 'input',
      props: {
        placeholder: '请输入电话',
      },
    },
  ],
});
queryDicByParent({ listDtos: ['ticketType'] }).then((res: any) => {
  data.columns[2].dic = [...res.ticketType];
});
</script>